package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkGenerateDialog

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkLineChart.GrammarLineChartManager
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TempletGrammarSpecificListInfor
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TopicGrammarKlgInfor
import com.luck.picture.lib.decoration.GridSpacingItemDecoration
import com.luck.picture.lib.tools.ScreenUtils
import kotlinx.android.synthetic.main.aibk_dialog_specific_grammar_analysis.*

/**
 * auther: 王国龙
 *  Date：2020.06.28
 * describe:答题返回弹窗
 */
class DialogSpecificGrammarAnalysis(
        context: Context?,
        val activity: AppCompatActivity,
        val templetGrammarSpecificListInfor: TempletGrammarSpecificListInfor,
        val indexA:Int,
        val indexB:Int,
        val isAllAnalysis:Boolean,
        val topicGrammarKlgInfor: TopicGrammarKlgInfor
) : Dialog(context!!, R.style.CustomDialog) {
    /**
     * 提交按钮
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aibk_dialog_specific_grammar_analysis)
        window!!.setGravity(Gravity.BOTTOM) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogBottomTranslate) //设置动画效果

        val wl = window!!.attributes
        //以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        onWindowAttributesChanged(wl)
        setCanceledOnTouchOutside(false)

        //初始化界面数据
        initView()
    }

    /**
     * 初始化界面控件的显示数据
     */
    private fun initView() {

        var singleRecommendationIndex:Number
        if(isAllAnalysis){
            singleRecommendationIndex = templetGrammarSpecificListInfor[indexA].RecommendationIndex
        }else{
            singleRecommendationIndex = templetGrammarSpecificListInfor[indexA].SubTopicList[indexB].RecommendationIndex
        }
        //不可选择的starBar，只做显示用  不显示空心
        RecommendStarBar.isClickable = false
        if(singleRecommendationIndex.toFloat()>singleRecommendationIndex.toInt()) {
            RecommendStarBar.numStars = singleRecommendationIndex.toInt()+1
        }else{
            RecommendStarBar.numStars = singleRecommendationIndex.toInt()
        }
        RecommendStarBar.rating = singleRecommendationIndex.toFloat()

        //加载专题语法维度分析
        var manager = LinearLayoutManager(activity)
        manager.orientation = LinearLayoutManager.HORIZONTAL
        RvSpecificAnalysis.layoutManager = manager
        val mAdapter1 = AibkSpecificAnalysisAdapter(activity,templetGrammarSpecificListInfor,indexA,indexB,isAllAnalysis)
        RvSpecificAnalysis.adapter = mAdapter1
        RvSpecificAnalysis.addItemDecoration(GridSpacingItemDecoration(
                3, ScreenUtils.dip2px(activity, 6f), false
        ))

        //关闭dialog
        IvCloseDialog.setOnClickListener {
            dismiss()
        }

        //显示曲线图表
        val lineChartManager = GrammarLineChartManager(LineChartAnalysis)
        //展示图表
        lineChartManager.showLineChart(topicGrammarKlgInfor, "专题对应知识点认知分析", activity.resources.getColor(R.color.lineChartLineGreen))
        //设置曲线填充色 以及 MarkerView
        val drawable: Drawable = activity.resources.getDrawable(R.drawable.aibk_fade_green)
        lineChartManager.setChartFillDrawable(drawable)
        lineChartManager.setMarkerView(activity,topicGrammarKlgInfor)

    }

//    private var clickDialogListener: onClickDialogListener? = null
//
//    /*
//   * 设置答题卡题号点击事件
//   * */
//    interface onClickDialogListener {
//        fun onClickCancel()//不再提醒
//        fun onClickQuit()//确认
//    }
//
//    fun setClickDialogListener(clickDialogListener: onClickDialogListener?) {
//        this.clickDialogListener = clickDialogListener
//    }
}